I know, I know. I read the latest forum discussions on this topic and thought I had a slam dunk, as far as updating an enumerated attribute in several modules, based on updates that were made to it in the "original" module. I used the Help files and this forum, but I still get a syntax error with the modify call. I have an enum named "Category", of base type "Enumeration" and I combined the available snippets from the Help files to come up with the following, for updating the "Category" attribute so that the list of available choices includes the seven items listed below: |
Re: Modify and Existing Enumerated Attribute Attachments attachment_14277835_Modify_Enumerated_Type.dxl |
Re: Modify and Existing Enumerated Attribute ChrisAnnal - Thu Jul 23 18:38:32 EDT 2009
[1] It doesn't like using constant arrays as parameters. You'll need to define your arrays as variables and then use them as parameters.
Module m = current
AttrType atype = find(m,"Category")
string sBaseType = stringOf(atype.type)
if(sBaseType == "Enumeration")
{
string Codes[] = {"Literature","Rack","Standup","What","Parent","Phase 2","N/A")
int Valus[] = {0,1,2,3,4,5,6}
int Color[] = {-1,-1,-1,-1,-1,-1,-1}
int Map[] = {0,1,2,3,4,5,6}
string ErrMess = ""
setRealColorOptionForTypes (true)
AttrType atNew = modify(atype,"Category", Codes, Valus, Color, Map, ErrMess)
// if (null atNew or !null ErrMess) we got an error
}
|
Re: Modify and Existing Enumerated Attribute llandale - Fri Jul 24 11:19:35 EDT 2009
[1] It doesn't like using constant arrays as parameters. You'll need to define your arrays as variables and then use them as parameters.
Module m = current
AttrType atype = find(m,"Category")
string sBaseType = stringOf(atype.type)
if(sBaseType == "Enumeration")
{
string Codes[] = {"Literature","Rack","Standup","What","Parent","Phase 2","N/A")
int Valus[] = {0,1,2,3,4,5,6}
int Color[] = {-1,-1,-1,-1,-1,-1,-1}
int Map[] = {0,1,2,3,4,5,6}
string ErrMess = ""
setRealColorOptionForTypes (true)
AttrType atNew = modify(atype,"Category", Codes, Valus, Color, Map, ErrMess)
// if (null atNew or !null ErrMess) we got an error
}
That pretty much did the trick, thanks!! There was a slight modification because DOORS didn't like the variables being declared in the body of the "if" statement, and for some reason, I had to use parenthesis ( ) instead of curly braces { } for the values of string codes, but it worked like a charm!! Here's what I ended up with. It runs super fast in an open module. Thanks again!! Chris // <Modify Enumerated Type.dxl> - Modify an existing Enumerated attribute. /* To modify this script, simply change the attribute type "Category" in the two places where it appears in the script below to the name of the existing enumerated attribute you want to modify. Also, for the codes in parenthesis below, change the items in parenthesis "Literature", "Rack", etc to the actual ones you want to use. For colors, "-1" means you don't want to change them, whatever they are. This script assumes 7 values are being changed, and that they are listed starting at the number "0". It's important to keep the same number of items for each variable. That is, if you add to the list or shorten it, you should do the same for all the variables, to keep them in synch. */ Module m = current AttrType atype = find(m,"Category") string sBaseType = stringOf(atype.type) string codes[]= ("Literature","Rack","Standup","What","Parent","Phase 2","N/A") int values[] = {0,1,2,3,4,5,6} int colors[] = {-1,-1,-1,-1,-1,-1,-1} int arrMaps[] = {0,1,2,3,4,5,6} string ErrMess = "" if(sBaseType == "Enumeration") { setRealColorOptionForTypes (true) AttrType atNew = modify(atype,"Category", codes, values, colors, arrMaps, ErrMess) // if (null atNew or !null ErrMess) we got an error } P.S. How did you get your text to be "colorized" in your reply? That's pretty cool. |
Re: Modify and Existing Enumerated Attribute ChrisAnnal - Tue Jul 28 10:00:41 EDT 2009 Surprised it doesn't like the arrays declared inside the 'if'. I never do that anyway.
|
Re: Modify and Existing Enumerated Attribute llandale - Tue Jul 28 10:07:42 EDT 2009
|
Re: Modify and Existing Enumerated Attribute SystemAdmin - Thu Jan 26 15:48:21 EST 2012
Use the above techniques where your "matching" array matches positions exactly:
-Louie |
Re: Modify and Existing Enumerated Attribute llandale - Fri Jan 27 09:45:57 EST 2012
Use the above techniques where your "matching" array matches positions exactly:
-Louie Thanks for all the information provided...I was able to create something that will allow me to loop thru all related module and make the changes to the attribute without having to compromise the data.
//This program was intended to replace the values of an enumerated attribute
//The replace will not affect the current selected values, it will just change the value to the new one
pragma runLim, 0
void replaceAttributeTypeValue(Module m, string atName, string oldVal, string newVal){
AttrType att = find(m, atName)
//Declare Arrays Size
int colores[att.size]
int arrMap[att.size]
string arr[att.size]
int arrVal[att.size]
int i
//Populate Arrays
for(i = 0; i < att.size; i++){
arr[i] = att.strings[i]
arrVal[i] = i
colores[i] = -1
arrMap[i] = i
}
//
for(i = 0; i < sizeof(arr); i++){
if(arr[i] == oldVal){
arr[i] = newVal
}
}
string err = null
AttrType at2 = modify(att, "Allocation", arr, arrVal, colores, arrMap, err)
if(!null err){
print "Failed: " err"\n"
}
else{
infoBox at2.name " - Modified Successfully"
}
}
|
Re: Modify and Existing Enumerated Attribute llandale - Fri Jan 27 09:45:57 EST 2012
Use the above techniques where your "matching" array matches positions exactly:
-Louie There is nothing in the DXL Reference Manual with this information. |
Re: Modify and Existing Enumerated Attribute SystemAdmin - Mon Jan 30 09:13:02 EST 2012 Thanks for all the information provided...I was able to create something that will allow me to loop thru all related module and make the changes to the attribute without having to compromise the data.
//This program was intended to replace the values of an enumerated attribute
//The replace will not affect the current selected values, it will just change the value to the new one
pragma runLim, 0
void replaceAttributeTypeValue(Module m, string atName, string oldVal, string newVal){
AttrType att = find(m, atName)
//Declare Arrays Size
int colores[att.size]
int arrMap[att.size]
string arr[att.size]
int arrVal[att.size]
int i
//Populate Arrays
for(i = 0; i < att.size; i++){
arr[i] = att.strings[i]
arrVal[i] = i
colores[i] = -1
arrMap[i] = i
}
//
for(i = 0; i < sizeof(arr); i++){
if(arr[i] == oldVal){
arr[i] = newVal
}
}
string err = null
AttrType at2 = modify(att, "Allocation", arr, arrVal, colores, arrMap, err)
if(!null err){
print "Failed: " err"\n"
}
else{
infoBox at2.name " - Modified Successfully"
}
}
So you can change "Medium" to "Moderate". OK.
.
for(i = 0; i < att.size; i++){
arr[i] = att.strings[i]
arrVal[i] = att.values()
colores[i] = att.colors()
arrMap[i] = i
}
maybe you can verify or contradict that.
|